﻿using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using System.Web;
using YouHP.Model.Group;

namespace YouHP.Pages
{
    public class SymptomList : BasePage
    {
        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected List<TopicInfo> TopicDataListHottest;
        protected List<TopicInfo> TopicDataListLatest;
        protected List<UserInfo> UserDataListLatest;

        protected List<SymptomInfo> SymptomDataList;
        protected List<DiseaseInfo> DiseaseLst;
        protected int SymptomCount = 0;
        protected int SymptomPageCount = 0;
        protected int SymptomPageSize = 15;
        protected int SymptomPageIndex = 1;
        protected string SymptomPagingString;

        protected SymptomSearchConditon cond = null;

        protected void HandleCommon()
        {
            this.AddLocation("症状列表", "/SymptomAll.aspx");
            DiseaseLst = DiseaseBLL.Instance.GetAllDiseaseByName("");
        }

        protected void HandlePost()
        {

        }

        protected void HandleGet()
        {
            int topiccnt = 8;
            TopicDataListHottest = TopicBLL.Instance.GetHottestTopic(topiccnt);
            TopicDataListLatest = TopicBLL.Instance.GetLastestTopic(topiccnt);

            cond = new SymptomSearchConditon();
            cond.DiseaseId = RequestTools.GetInt("dszid", 0);
            cond.DiseaseName = RequestTools.GetString("dszname").Trim();
            cond.SymptomName = RequestTools.GetString("symname").Trim();

            SymptomPageIndex = RequestTools.GetQueryInt("page", 1);

            SymptomDataList = SymptomBLL.Instance.GetSymptomList(
                SymptomPageSize,SymptomPageIndex,
                cond, out SymptomCount);

            SymptomPageCount = Utils.GetPageCount(SymptomCount, SymptomPageSize);

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query, "page");

            SymptomPagingString = this.GetPagingString(
                SymptomPageIndex,
                SymptomPageCount,
                "/SymptomList.aspx" + query, "page");
        }

        protected string GetCondStr(SymptomSearchConditon cond)
        {
            string condStr = String.Empty;
            bool firstCond = true;

            if (cond == null)
            {
                return string.Empty;
            }

            if (cond.DiseaseId > 0)
            {
                condStr += DiseaseBLL.Instance.GetDiseaseInfo(cond.DiseaseId).Name;
                firstCond = false;
            }

            if (cond.SymptomName.Length > 0)
            {
                if (!firstCond)
                {
                    condStr += " + ";
                }
                condStr += cond.SymptomName ;
                firstCond = false;
            }

            return condStr;
        }
    }
}